package com.jiangjiang.eshop.wms.chain;

import com.jiangjiang.eshop.wms.dto.PurchaseInputOrderDTO;
import com.jiangjiang.eshop.wms.dto.PurchaseInputOrderHandlerResult;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author Jianghaowen
 * @Date 2021/9/14
 * @Description: TODO
 * @Version V1.0
 **/
public abstract class AbstractPurchaseInputOrderHandler implements PurchaseInputOrderHandler {

    /**
     * 后继结点
     */
    private PurchaseInputOrderHandler successor;

    /**
     * 设置后继节点
     * @param successor
     * @return
     */
    public void setSuccessor(PurchaseInputOrderHandler successor) {
        this.successor = successor;
    }


    @Override
    public Boolean execute(PurchaseInputOrderDTO dto) throws Exception {
        PurchaseInputOrderHandlerResult result = doExecute(dto);
        if (successor != null && result.getDoNext()) {
            successor.execute(dto);
        }
        return result.getResult();
    }

    /**
     * 执行当前链条结点业务逻辑
     *
     * @param dto 采购入库单
     * @throws Exception
     * @return 处理结果
     */
    protected abstract PurchaseInputOrderHandlerResult doExecute(PurchaseInputOrderDTO dto) throws Exception;
}
